package com.demo.service.sys.impl;

import com.demo.common.constant.api.base.BaseServiceImpl;
import com.demo.dao.sys.entity.SysUserItem;
import com.demo.service.sys.SysUserService;
import org.apache.poi.ss.usermodel.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

@Service
public class SysUserServiceImpl extends BaseServiceImpl<SysUserItem, Long>
        implements SysUserService {


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void importExcel(MultipartFile file) throws Exception {
        if (file != null) {
            InputStream inputStream = file.getInputStream();
            Workbook workbook = WorkbookFactory.create(inputStream);
            Sheet sheet = workbook.getSheetAt(0);
            int rowNumber = sheet.getPhysicalNumberOfRows();
            SysUserItem sysUserItem = null;
            for (int i = 1; i < rowNumber; i++) {
                Row row = sheet.getRow(i);
                Cell cell1 = row.getCell(1);
                if (!ObjectUtils.isEmpty(cell1.getStringCellValue().trim())) {
                    sysUserItem = new SysUserItem();
                    sysUserItem.setId(Long.parseLong(cell1.getStringCellValue().trim()));

                }
            }
        }
    }
}
